#include "general.h"

CDataServer::CDataServer()
    :   dbus::CObject(nDBusTree,"/org/buola/BigBrother/data")
{
}

CDataServer::~CDataServer()
{
}

void CDataServer::DBusCall(dbus::CMessage *pMessage)
{
    const std::string &lMethod=pMessage->GetMember();

    if(lMethod=="GetMetadata")
    {
        std::string lFolder=pMessage->Extract<std::string>();
        std::string lName=pMessage->Extract<std::string>();
        std::string lKey=pMessage->Extract<std::string>();
        
        UValue lValue;
        
        GetMetadata(lFolder,lName,lKey,lValue);
//      lFolder->GetValue(lName,lKey,lValue);
        dbus::CReply *lReply=pMessage->BuildReply();
        if(!lValue.empty())
            lReply->Append(lValue);
        lReply->Send();
    }
    else if(lMethod=="SetMetadata")
    {
        //STRING:folder STRING:name STRING:key STRING:value
        std::string lFolder=pMessage->Extract<std::string>();
        std::string lName=pMessage->Extract<std::string>();
        std::string lKey=pMessage->Extract<std::string>();

        SetMetadata(lFolder,lName,lKey,pMessage->Extract<UValue>());

        dbus::CReply *lReply=pMessage->BuildReply();
        lReply->Send();
    }
    else if(lMethod=="GetMimeTypes")
    {
        //STRING:folder
        std::string lFolder=pMessage->Extract<std::string>();

        dbus::CReply *lReply=pMessage->BuildReply();
        GetMimeTypes(lFolder,lReply);
        lReply->Send();
    }
    else
    {
        dbus::CReply *lReply=pMessage->BuildReply();
        lReply->Send();
    }
}
